#ifndef BASE_SYSTEM_LOG_LOGGER_INCLUDE_GLOBAL_LOGGER_H
#define BASE_SYSTEM_LOG_LOGGER_INCLUDE_GLOBAL_LOGGER_H

#include <memory>
#include "async_logger.h"
#include "console_output_strategy.h"
#include "file_output_strategy.h"
#include "system_log_config.h"

namespace Base {
namespace SystemLog {
class GlobalLogger {
public:
    static GlobalLogger &GetInstance() {
        static GlobalLogger instance;
        return instance;
    }

    AsyncLogger<> &GetLogger() {
        return AsyncLogger<>::GetInstance();
    }

    void Initialize(LogLevel level = LOG_LEVEL_TRACE, bool enableLogFileOutput = true,
        [[maybe_unused]]size_t maxFileSize = DEFAULT_MAX_FILE_SIZE) {
        //设置日志级别
        AsyncLogger<>::GetInstance().SetMinLevel(level);

        // 添加控制台输出
        AsyncLogger<>::GetInstance().AddOutputStrategy(std::make_unique<ConsoleOutputStrategy>());

        // 如果使能日志文件输出，添加文件输出
        if (enableLogFileOutput) {
            FileOutputOptions options;
            AsyncLogger<>::GetInstance().AddOutputStrategy(std::make_unique<FileOutputStrategy>(options));
        }

        // 启动日志器
        AsyncLogger<>::GetInstance().Start();
    }

    void Shutdown() {
        AsyncLogger<>::GetInstance().Stop();
    }

private:
    GlobalLogger() {
        Initialize(LOG_LEVEL_TRACE);
    }
    ~GlobalLogger() {
        Shutdown();
    }
};
} // namespace SystemLog
} // namespace Base
#endif // BASE_SYSTEM_LOG_LOGGER_INCLUDE_GLOBAL_LOGGER_H